package com.derbysoft.synxisadapter.action.monitor.transactionlog;

import com.derbysoft.core.LimitedList;
import com.derbysoft.synxisadapter.action.DMXAbstractAction;
import com.derbysoft.synxisadapter.commons.model.TransactionLog;
import com.derbysoft.synxisadapter.commons.repository.TransactionLogRepository;
import com.derbysoft.synxisadapter.commons.repository.impl.DMXTransactionLogCondition;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * User: jason
 * Date: 2013-02-20
 */
public class DMXAction extends DMXAbstractAction {

    @Autowired
    private TransactionLogRepository transactionLogRepository;

    private DMXTransactionLogCondition condition = new DMXTransactionLogCondition();

    @Action("dmxTransactionLog")
    public String dmxQuery() {
        try {
            LimitedList<TransactionLog> limitedList = transactionLogRepository.findByCondition(condition, createLimit());
            return populateSucceededJsonResult(dmxPaging(limitedList, super.getPage(), limitedList.getTotalcount()));
        } catch (Exception ex) {
            return populateFailedJsonResult(ex);
        }
    }

    @Action("dmxViewDetail")
    public String dmxViewDetail() {
        try {
            if (condition == null || condition.getId() == null) {
                return populateSucceededJsonResult("");
            }
            return populateSucceededJsonResult(transactionLogRepository.findById(condition.getId()),"transactionLog");
        } catch (Exception ex) {
            return populateFailedJsonResult(ex);
        }
    }

    public DMXTransactionLogCondition getCondition() {
        return condition;
    }

    public void setCondition(DMXTransactionLogCondition condition) {
        this.condition = condition;
    }
}
